package com.brotherly.geo;

import java.util.Map;

public class MapHelper
{
    @SuppressWarnings("rawtypes")
    public static String getString(Map map, Object key)
    {
        if (!map.containsKey(key))
            return null;

        Object value = map.get(key);
        if (value instanceof String)
            return (String) value;

        if (value == null)
            return "";

        return value.toString();
    }

    @SuppressWarnings("rawtypes")
    public static Number getNumber(Map map, Object key)
    {
        if (!map.containsKey(key))
            return Integer.valueOf(0);

        Object value = map.get(key);
        if (value instanceof Number)
            return (Number) value;

        if (value == null)
            return Integer.valueOf(0);

        return Double.valueOf(value.toString());
    }

    @SuppressWarnings("rawtypes")
    public static Boolean getBoolean(Map map, Object key)
    {
        if (!map.containsKey(key))
            return Boolean.FALSE;

        Object value = map.get(key);
        if (value instanceof Boolean)
            return (Boolean) value;

        if (value == null)
            return Boolean.FALSE;

        return Boolean.valueOf(value.toString());
    }
}
